class TagController < ApplicationController
  before_filter :login_required, :only=>:add_tag
  def view
    @tag = params[:id]
    @things = Thing.find_tagged_with @tag
    @things.sort
  end

  def add_tag
    @thing = Thing.find params[:id]
    @thing.tag_list.clear
    for tag in params[:tags].split
      @thing.tag_list << tag
    end
    @thing.save
    flash[:notice] = "更新成功！"
    redirect_to :controller=>:things, :action => :view, :id=>@thing
  end

  def list_things
    @tag = params[:id]
    @things = Thing.find_tagged_with @tag
    @things.sort
  end
end
